package gdut.stream.last;

import java.util.ArrayList;
import java.util.Optional;
import java.util.function.Consumer;

public class ParallelStreamTest {
    public static void main(String[] args) {
        ArrayList<Integer> integers = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            integers.add(i);
        }
        Optional<Integer> res = integers.stream().parallel()
                .peek(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) {
                        System.out.println(integer + Thread.currentThread().getName());
                    }
                })
                .filter(num -> num < 10)
                .reduce((result, element) -> result + element);
        res.ifPresent(System.out::println);
    }
}
